package cn.edu.ujn.lab1.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.ujn.lab1.model.Student;
@Repository
@Transactional
public class StudentDaoImpl implements IStudentDao {
	@Autowired
	private JdbcTemplate jdbcTemplate;
	@Override
	public Student addStudent(Student stu) {
		// TODO 自动生成的方法存根
		String sql="insert into student(uid,stunumber,stuname) values(?,?,?)";
		Object[] obj=new Object[] {stu.getUid(),stu.getStunumber(),stu.getStuname()};
		int update = this.jdbcTemplate.update(sql, obj);
		if(update>0) {
			return stu;
		}
		return null;
	}

	@Override
	public List<Student> findAllStudent() {
		// TODO 自动生成的方法存根
		String sql="select * from student";
		BeanPropertyRowMapper<Student> mapper = new BeanPropertyRowMapper<Student>(Student.class);
		return this.jdbcTemplate.query(sql,mapper);
	}

}
